<?php
/*
 *
 */
class action extends app{
	public function display(){
		$action = $this->routes->url(3);
		if(!method_exists($this,$action))
		$action = "index";
		$this->$action();
		exit;
	}

	private function index(){
		$this->G->loadclass('tinwin')->GetWebContent(SITE_WEB.'/index.php?home-web-createhtml-createindex');
		echo "生成成功";
	}

	private function createindex(){
		$WebConfig=$this->G->loadclass('webconfig')->getWebConfig();
		$this->tpl->MakeHtml('index','./index.html',HOMENAME.'/view/'.$WebConfig['website']['homeskin'].'/web/');
	}

	private function createcat(){
		$WebConfig=$this->G->loadclass('webconfig')->getWebConfig();
		$IntCid=$this->routes->get('cid');
		$MyCat=$this->category->getOne(array('id'=>$IntCid));
		$page = intval($this->routes->get('page'));
		$page = $page>0?$page:1;
		if($MyCat){
			$this->files->mdir('./'.$MyCat['catalog_name']);
			$ListApps=$this->apps->getAllByData();
			$cids=$this->category->getCids(array('parent_id'=>$MyCat['id']));
			if($cids){
				$cids=$cids.','.$MyCat['id'];
			}else{
				$cids=$MyCat['id'];
			}
			$condition="FIND_IN_SET(cat_id,'".$cids."')";
			$ListArt=$this->article->getList($page,$MyCat['cat_pagenum'],$condition,'list');
			if($page>$ListArt['total']&&$page>1){
				$message = array(
					'statusCode' =>300,
					"message" => "请勿乱策",
					"callbackType" =>'forward',
					"forwardUrl" =>"goback"
				);
				$this->G->R($message);
			}
			$NavCrumb=$this->category->getNavCrumbByCid($MyCat['id']);
			$ListCatSun=$this->category->getSunByCid($MyCat['id']);
			if(empty($ListCatSun)){
				if($MyCat['parent_id']==0){
					$ListCatSun=$this->category->getAll(array('id'=>$MyCat['id']));
				}else{
					$ListCatSun=$this->category->getSunByCid($MyCat['parent_id']);
				}
			}
			$ListArtHot=$this->article->getSpecialArt($MyCat['id'],$MyCat['cat_pagenum'],'view desc');
			$ListArtNew=$this->article->getSpecialArt($MyCat['id'],$MyCat['cat_pagenum'],'addtime desc');
			$this->tpl->assign("ListArtNew",$ListArtNew);
			$this->tpl->assign("ListArtHot",$ListArtHot);
			$this->tpl->assign("ListApps",$ListApps);		
			$this->tpl->assign("MyCat",$MyCat);
			$this->tpl->assign("NavCrumb",$NavCrumb);
			$this->tpl->assign("Catalog",$MyCat['catalog_name']);
			$this->tpl->assign("ListArt",$ListArt);
			$this->tpl->assign("ListCatSun",$ListCatSun);
			$SeoTitle=$MyCat['seo_title']!=''?$MyCat['seo_title']:$MyCat['cat_name'];
			$SeoKeywords=$MyCat['seo_keywords']!=''?$MyCat['seo_keywords']:$MyCat['cat_name'];
			$SeoDescription=$MyCat['seo_description']!=''?$MyCat['seo_description']:$MyCat['cat_name'];
			if($page>1){
				$this->tpl->assign("SeoTitle",$SeoTitle.' 第'.$page.'页');
			}else{
				$this->tpl->assign("SeoTitle",$SeoTitle);
			}
			$this->tpl->assign("SeoKeywords",$SeoKeywords);
			$this->tpl->assign("SeoDescription",$SeoDescription);
            if(empty($MyCat['cat_skin'])){
                $MyCat['cat_skin']='category_view';
            }
            $this->tpl->MakeHtml($MyCat['cat_skin'],'./'.$MyCat['catalog_name'].'/index.html',HOMENAME.'/view/'.$WebConfig['website']['homeskin'].'/web/');
		}else{
			header("location:/404.html");
		}
	}

	private function createart(){
		$IntID=$this->routes->get('id');
		$IntID = $IntID > 0?$IntID:1;
		$artme = $this->article->getOneByID($IntID);
		if($artme){
			$WebConfig=$this->G->loadclass('webconfig')->getWebConfig();
			$MyCat=$this->category->getOne(array('id'=>$artme['cat_id']));
			$this->files->mdir('./'.$MyCat['catalog_name']);
			$Content=$artme['content'];
            if($this->apps->getOneByName('links')){
                $SetLink=$this->search->setInLinkByContent($Content);//加载内链
                if($SetLink){
                    $artme['content']=$SetLink;
                }
            }
			$this->tpl->assign("ListArtNew",$this->article->getSpecialArt($MyCat['id'],$MyCat['cat_pagenum'],'addtime desc'));
			$this->tpl->assign("ListArtHot",$this->article->getSpecialArt($MyCat['id'],$MyCat['cat_pagenum'],'view desc'));
			$ListCatSun=$this->category->getSunByCid($MyCat['id']);
			if(empty($ListCatSun)){
				if($MyCat['parent_id']==0){
					$ListCatSun=$this->category->getAll(array('id'=>$MyCat['id']));
				}else{
					$ListCatSun=$this->category->getSunByCid($MyCat['parent_id']);
				}
			}
			$this->tpl->assign("ListCatSun",$ListCatSun);
			$this->tpl->assign('preArt',$this->article->getPreByID($IntID));//上一篇
			$this->tpl->assign('nextArt',$this->article->getNextByID($IntID));//下一篇
			$this->tpl->assign('NavCrumb',$this->article->getNavCrumbByAid($IntID));//面包屑导航
			$this->tpl->assign('RelationArt',$this->tags->getRelationArtByAid($IntID));//相关文章
			$this->tpl->assign('HotArt',$this->article->getSpecialArt($MyCat['id'],$MyCat['cat_pagenum'],'view desc'));//热门文章
            $this->tpl->assign('stags',$this->tags->getTagByAid($IntID));//tag标签
			$nickname=$this->users->getOneByID($artme['adduser']);
			$artme['nickname']=$nickname['nickname'];
			$this->tpl->assign('artme',$artme);
            $this->tpl->assign('MyCat',$MyCat);
			$this->tpl->assign('SeoTitle',$artme['seo_title']=$artme['seo_title']!=""?$artme['seo_title']:$artme['title']);
			$this->tpl->assign('SeoKeywords',$artme['seo_keywords']=$artme['seo_keywords']!=""?$artme['seo_keywords']:$artme['seo_tags']);
            if(empty($artme['seo_description'])){
                $artme['seo_description']=substr(strip_tags(html_entity_decode($Content)),0,250);
            }
			$this->tpl->assign('SeoDescription',$artme['seo_description']);
			if(empty($MyCat['article_skin'])){
				$MyCat['article_skin']='article_view';
			}
			$this->tpl->MakeHtml($MyCat['article_skin'],'./'.$MyCat['catalog_name'].'/'.$IntID.'.html',HOMENAME.'/view/'.$WebConfig['website']['homeskin'].'/web/');
		}else{
			header("location:/404.html");
		}
	}

	private function artall(){
		$ListAll=$this->article->getAll('','id');
		foreach ($ListAll as $key => $value) {
			$this->G->loadclass('tinwin')->GetWebContent(SITE_WEB.'/index.php?home-web-createhtml-createart&id='.$value['id']);
		}
		echo "生成成功";
	}

	private function catall(){
		$ListAll=$this->category->getAll();
		foreach ($ListAll as $key => $value) {
			$this->G->loadclass('tinwin')->GetWebContent(SITE_WEB.'/index.php?home-web-createhtml-createcat&cid='.$value['id']);
		}
		echo "生成成功";
	}

	private function catone(){
		$IntID=$this->routes->get('cid');
		$IntID = $IntID > 0?$IntID:1;
		$MyCat=$this->category->getOne(array('id'=>$IntID));
		$this->G->loadclass('tinwin')->GetWebContent(SITE_WEB.'/index.php?home-web-createhtml-createcat&cid='.$MyCat['id']);
		$ListArt=$this->article->getAll(array('cat_id'=>$IntID));
		if(is_array($ListArt)){
			foreach ($ListArt as $key => $value) {
				$this->G->loadclass('tinwin')->GetWebContent(SITE_WEB.'/index.php?home-web-createhtml-createart&id='.$value['id']);
			}
		}
		echo "生成成功";
	}
}
?>
